1
2
3
4 package joeq.Runtime;
5
6 import joeq.Allocator.ObjectLayout;
7 import joeq.Class.jq_Array;
8 import joeq.Class.jq_Class;
9 import joeq.Class.jq_Reference;
10 import joeq.Memory.HeapAddress;
11 import jwutil.util.Assert;
12
13
14
15
16
17 public abstract class HashCode {
18
19 public static int identityHashCode(Object x) {
20 HeapAddress a = HeapAddress.addressOf(x);
21 int status = a.offset(ObjectLayout.STATUS_WORD_OFFSET).peek4();
22 if ((status & ObjectLayout.HASHED_MOVED) != 0) {
23 jq_Reference t = jq_Reference.getTypeOf(x);
24 if (t.isClassType()) {
25 jq_Class k = (jq_Class) t;
26 return a.offset(k.getInstanceSize() - ObjectLayout.OBJ_HEADER_SIZE).peek4();
27 }
28 Assert._assert(t.isArrayType());
29 jq_Array k = (jq_Array) t;
30 int arraylength = a.offset(ObjectLayout.ARRAY_LENGTH_OFFSET).peek4();
31 return a.offset(k.getInstanceSize(arraylength) - ObjectLayout.ARRAY_HEADER_SIZE).peek4();
32 }
33 a.offset(ObjectLayout.STATUS_WORD_OFFSET).poke4(status | ObjectLayout.HASHED);
34 return a.to32BitValue();
35 }
36
37 }